Android
Library that implements preferred units
Getting Started
- Example
- Installing
- Readme
- Changelog
- Start preferred units activity:
startActivity(HumaPreferredUnitsManager.getInstance().getPreferredUnitsActivityLauncherIntent(
context = this,
params = PreferredUnitsActivity.Params.OnboardingMode // intro screen, pref units screen
// params = PreferredUnitsActivity.Params.DefaultMode(isReadOnly = false) // no intro screen, pref units screen
))
- Get preferred units:
HumaPreferredUnitsManager.getInstance().getPreferredUnits(
onPreferredUnitsReady = { units: PreferredUnitsContainer -> /*..*/ },
onFailure = { error: Error -> /*..*/ }
)
- Get preferred unit selection view data:
HumaPreferredUnitsManager.getInstance().getPreferredUnitsSelectionViewData(
onViewDataReady = { viewData: List<PreferredUnitSelectionViewData> -> /*..*/ },
onFailure = { error: Error -> /*..*/ }
)
- Set preferred units:
HumaPreferredUnitsManager.getInstance().setPreferredUnits(
preferredUnits = listOf<PreferredUnitInfo>(),
onSuccess = { units: PreferredUnitsContainer -> /*..*/ },
onFailure = { error: Error -> /*..*/ }
)
- Add the dependency in your local build.gradle file:
implementation("com.huma.sdk:preferred-units:<latest-version>")
- Initialize
HumaPreferredUnitsManager
in your Application class:
HumaPreferredUnitsManager.init(
preferredUnitsConfig: PreferredUnitsConfig? = null
)
Customization
During HumaPreferredUnitsManager
initialization you can pass a PreferredUnitsConfig
instance containing a list of enabled measurement unit types. All default measurement unit types are open class
so that you can override its methods if needed.
Conversion
MeasurementUnitType<*>
classes have all required methods to convert the units. There's functions to get MeasurementUnitType<*>
or MeasurementUnit
from string id value - check com.huma.sdk.preferred_units.utils.ExtensionsKt
Displaying data
The library handles simple (100 cm) and composite (4 ft 0 in) values and units. To simplify the process UnitDisplayData
(which you can get for every MeasurementUnit
) takes Value
as input and produces ValueAndUnit
as output.
Documentation
Dependencies
[0.1.29]